package com.zsc.projectmanagementapi.controller;

import com.github.pagehelper.PageInfo;
import com.zsc.projectmanagementapi.commons.ServerResponse;
import com.zsc.projectmanagementapi.pojo.Do.ProjectState;
import com.zsc.projectmanagementapi.service.ProjectStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author LinHj
 * @date 2021/6/19 15:09
 **/
@RestController
@RequestMapping("/state")
public class ProjectStateController {

    @Autowired
    ProjectStateService projectStateService;

    @GetMapping("/getAllState")
    public ServerResponse getAllState(@RequestParam int page,
                                      @RequestParam int limit,
                                      @RequestParam(required = false) String projectName,
                                      @RequestParam(required = false) Integer importance,
                                      @RequestParam(required = false) String sort){
        PageInfo<ProjectState> allProjectsState = projectStateService.getAllProjectsState(page, limit,projectName,importance,sort);
        return ServerResponse.createBySuccess(allProjectsState);
    }

//    @GetMapping("/getAllState")
//    public ServerResponse getAllState(@RequestParam int page,@RequestParam int limit,@RequestParam String sort){
//        PageInfo<ProjectState> allProjectsState = projectStateService.getAllProjectsStateSort(page, limit,sort);
//        return ServerResponse.createBySuccess(allProjectsState);
//    }

    @PostMapping("/updateState")
    public ServerResponse updateState(@RequestBody ProjectState projectState){
        int i = projectStateService.updateProjectState(projectState);
        return ServerResponse.createBySuccess(i);
    }

    @PostMapping("/deleteState")
    public ServerResponse deleteState(@RequestParam String id){
        int i = projectStateService.deleteProjectStateById(id);
        return ServerResponse.createBySuccess(i);
    }
}
